package cn.lger.icollege.util;

import cn.lger.icollege.security.CommonUserDetails;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * Code that Changed the World
 * Pro said
 * Created by Pro on 2018-04-16.
 */
public class SecurityResourceUtil {

    public static String getUserDetailsUsername(){
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (principal instanceof UserDetails) {
            return ((CommonUserDetails)principal).getUsername();
        }
        throw new RuntimeException("用户未登录");
    }
}
